<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        // var //sum = 0,
        //     odd = 0,
        //     even = 0,
        //     num = 0;
        // for (var i = 1; i <= 100; i++) {
        //     // sum += i;
        //     i % 2 === 0 ? even += i : odd += i;
        //     if (i % 3 === 0) {
        //         num += i;
        //     }
        //     i % 3 || (num += i);
        // }
        // console.log(`1~100之间所有数的平均值为:${(odd + even) / (i - 1)}`);
        // console.log(`1~100之间奇数和为:${odd}`);
        // console.log(`1~100之间偶数和为:${even}`);
        // console.log(`1~100能被3整除数字的和为:${num}`);
        var num = prompt('请输入班级总人数') - 0,
            sum = 0,
            average = 0;
        while (!num || parseFloat(num) !== parseInt(num) || num < 0) {
            alert('输入有误,请重新输入');
            num = prompt('请输入班级总人数') - 0;
        }
        for (var i = 1; i <= num; i++) {
            var score = (prompt(`请输入第${i}个同学的成绩`) - 0);
            while (score !== 0 && !score || parseFloat(score) !== parseInt(score) || score < 0) {
                alert('输入有误,请重新输入')
                score = (prompt(`请输入第${i}个同学的成绩`) - 0);
            }
            sum += score;
        }
        average = sum / (i - 1);
        alert(`班级总成绩为:${sum}`)
        alert(`班级平均成绩为:${average}`)
    </script>
</head>

<body>

</body>

</html>